package ar.fi.uba.taller2.participacion.utils;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class UsuarioParserHandler extends DefaultHandler {

	private ArrayList<String> userList = new ArrayList<String>();
	private boolean bUsername = false;

	public void startDocument() throws SAXException {
		// System.out.println("start of the document   : ");
	}

	public void endDocument() throws SAXException {
		// System.out.println("end of the document document     : ");
	}

	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		if ("username".equals(qName)) {
			bUsername = true;
		}
	}

	public void endElement(String uri, String localName, String qName) throws SAXException {

	}

	public void characters(char[] ch, int start, int length) throws SAXException {
		if (bUsername) {
			String value = new String(ch, start, length).trim();

			if (value.length() == 0) {
				return; // ignore white space
			}

			userList.add(value);
			bUsername = false;

		}

	}

	public ArrayList<String> getUsers() {
		return userList;
	}
}
